package com.hellowx.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by IntelliJ IDEA.
 *
 * @author MagicMushroom
 * @date 2021/7/13
 */
@RestController
public class DemoController {

    @GetMapping("/demo/{id}")
    @HystrixCommand(fallbackMethod = "demoFallbackMethod")
    public String demo(@PathVariable("id")Integer id){
        if (id<0){
            throw new RuntimeException("无效id");
        }
        return "demo ok !!!!";
    }

    public String demoFallbackMethod(@PathVariable("id")Integer id){
        return "被熔断了！！！！";
    }
}
